package us.mooresr.aircraftscheduling.server.handler;



import us.mooresr.aircraftscheduling.server.DAO;
import us.mooresr.aircraftscheduling.server.MailNotifier;
import us.mooresr.aircraftscheduling.shared.action.CreateReservationAction;
import us.mooresr.aircraftscheduling.shared.action.CreateReservationResult;
import us.mooresr.aircraftscheduling.shared.model.Reservation;

import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class CreateReservationHandler 
	implements ActionHandler<CreateReservationAction, CreateReservationResult> {

	@Override
	public CreateReservationResult execute(CreateReservationAction action,
			ExecutionContext context) throws ActionException {
		DAO dao = new DAO();
		
		Reservation newReservation = action.getReservation();
		
		dao.ofy().put(newReservation);
		
		CreateReservationResult result = new CreateReservationResult(newReservation);
		
		MailNotifier.getInstance().sendNewReservationNotifications(newReservation);
		
		return result;
	}

	@Override
	public Class<CreateReservationAction> getActionType() {
		return CreateReservationAction.class;
	}

	@Override
	public void undo(CreateReservationAction action,
			CreateReservationResult result, ExecutionContext context)
			throws ActionException {

		
	}

}
